package com.minivision.fdiot.exception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.minivision.fdiot.common.RestResult;
import com.minivision.fdiot.rest.result.ResultError;

@RestControllerAdvice
public class FacePlatExcetionHandler {
  
  @ExceptionHandler(FacePlatException.class)
  @ResponseBody
  public RestResult<ResultError> handleFacePlatException(HttpServletRequest request, FacePlatException ex) {
      RestResult<ResultError> restResult = new RestResult<>();
      ResultError re = new ResultError();
      re.setErrorMessage(ex.getMessage());
      re.setErrorCode(ex.getErrCode());
      re.setPath(request.getRequestURI());
      re.setTimestamp(System.currentTimeMillis());
      restResult.setData(re);
      restResult.setStatus(-1);
      return restResult;
  }
  
  @ExceptionHandler(IllegalArgumentException.class)
  @ResponseBody
  public RestResult<ResultError> handleArgException(HttpServletRequest request, IllegalArgumentException ex) {
      ResultError re = new ResultError();
      re.setErrorMessage(ex.getMessage());
      re.setErrorCode(HttpStatus.BAD_REQUEST.value());
      re.setPath(request.getRequestURI());
      re.setTimestamp(System.currentTimeMillis());
      return new RestResult<>(re);
  }
  
}
